import com.imooc.spring.jdbc.dao.EmployeeDao;
import com.imooc.spring.jdbc.entity.Employee;
import com.imooc.spring.jdbc.service.EmployeeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class jdbcTemplateTestor {
    @Resource
    private EmployeeDao employeeDao;

    @Resource
    private EmployeeService employeeService;

    @Test
    public void testFindById() {
        Employee employee = employeeDao.findById(1);
        System.out.println(employee);
    }

    @Test
    public void testfindByDname() {
        List<Employee> employees = employeeDao.findByDname("研发部");
        System.out.println(employees);
    }

    @Test
    public void testfindMapByname() {
        System.out.println(employeeDao.findMapByname("研发部"));
    }

    @Test
    public void testInsertEmployee() {
        Employee employee = new Employee();
        employee.setEno(666);
        employee.setEname("小明");
        employee.setSalary(Float.valueOf(7000F));
        employee.setDname("市场部");
        employee.setHiredate(new Date());
        employeeDao.insertEmployee(employee);
    }

    @Test
    public void testUpdateEmployee() {
        Employee employee = employeeDao.findById(666);
        employee.setSalary(employee.getSalary() + 1000);
        int count = employeeDao.updateEmployee(employee);
        System.out.println("本次更新" + count + "数据");
    }

    @Test
    public void testDeleteEmployee() {
        int count = employeeDao.deleteEmployee(3);
        System.out.println("本次更新" + count + "数据");
    }

    @Test
    public void testBatchImport() {
        employeeService.batchImport();
        System.out.println("批量导入成功");
    }
}
